package luren.king.wechatlite.ui;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

import luren.king.wechatlite.R;
import luren.king.wechatlite.adapter.ContactAdapter;
import luren.king.wechatlite.pojo.Contact;

public class ContactsFragment extends Fragment {
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_contacts,container,false);
        RecyclerView friends = view.findViewById(R.id.contacts_all);
        // 创建LinearLayoutManager对象，用于管理recyclerView的布局
        LinearLayoutManager manager = new LinearLayoutManager(getContext());

        // 设置recyclerView的布局管理器
        friends.setLayoutManager(manager);

        // 设置recyclerView的滚动方向为垂直
        manager.setOrientation(RecyclerView.VERTICAL);

        // 为recyclerView添加分割线装饰
        friends.addItemDecoration(new DividerItemDecoration(requireContext(), 1));

        List<Contact> friend = new ArrayList<>();

        // 从数据库获取联系人列表


        Contact contact = new Contact();
        contact.setName("聊天对象                              ");
//        contact.setEmail("11111@qq.com");

        friend.add(contact);

        ContactAdapter adapter = new ContactAdapter(getContext(), friend);

        friends.setAdapter(adapter);

        return view;
    }
}
